
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :Sindy
	CreateTime:2008-01-30 15:18:36
*/
public class InoutTypeSrv extends IHandler
{

	public InoutTypeSrv() 
	{
		super();
	}
	private void deleteInoutType(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		InoutType obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = InoutType.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveInoutType(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		InoutType obj;
		
		InoutTypePageData data = (InoutTypePageData)PageData.fromForm(context,InoutTypePageData.class);
		if((id==null)||(id.equals("")))   //add
		{
			obj = InoutType.fetch();
			data.setCreateUserId(loginContext.getLoginUserId());
            data.setCreateUser(loginContext.getLoginUserName());
            data.setCreateTime(new DateUtil().getFullString());
    	}
    	else                     //update
    	{
    		obj = InoutType.fetch(con,id);
    	}
		data.setLastUpdateUserId(loginContext.getLoginUserId());
        data.setLastUpdateUser(loginContext.getLoginUserName());
        data.setLastUpdateTime(new DateUtil().getFullString());
        
		context.setValue("InoutTypePageData",data);
		obj.fill(data);
	    obj.save(con);
	}
	private void listInoutType(DBConnection con,SrvContext context,String path) throws Exception
	{
		InoutTypeSearchEvent event = (InoutTypeSearchEvent)SearchEvent.fromForm(context,InoutTypeSearchEvent.class);
		context.setSessionValue("InoutTypeSearchEvent",event);
		context.setNextUrl(path+"InoutTypeList.jsp");
	}
	private void backInoutType(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"InoutTypeList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listInoutType"))
		{
			listInoutType(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewInoutType"))
		{
			String id = context.getString("Id",null);
			InoutType obj = InoutType.fetch(con,id);
			context.setValue("InoutType",obj);
			context.setNextUrl(path+"InoutTypeView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteInoutType"))
		{
			context.setErrorUrl(path+"InoutTypeList.jsp");
			deleteInoutType(con,context);
			backInoutType(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddInoutType"))
		{
			InoutType obj = InoutType.fetch();
			InoutTypePageData data = (InoutTypePageData)PageData.fromTable(obj,InoutTypePageData.class);
			context.setValue("InoutTypePageData",data);
			context.setNextUrl(path+"InoutTypeEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateInoutType"))
		{
			String id = context.getString("Id",null);
			InoutType obj = InoutType.fetch(con,id);
			InoutTypePageData data = (InoutTypePageData)PageData.fromTable(obj,InoutTypePageData.class);
			context.setValue("InoutTypePageData",data);
			context.setNextUrl(path+"InoutTypeEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyInoutType"))
		{
			String id = context.getString("Id",null);
			InoutType obj = InoutType.copy(InoutType.fetch(con,id));
			InoutTypePageData data = (InoutTypePageData)PageData.fromTable(obj,InoutTypePageData.class);
			context.setValue("InoutTypePageData",data);
			context.setNextUrl(path+"InoutTypeEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveInoutType"))
		{
			context.setErrorUrl(path+"InoutTypeEdit.jsp");
			saveInoutType(con,context,loginContext);
			backInoutType(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewInoutType"))
		{
			context.setErrorUrl(path+"InoutTypeEdit.jsp");
			saveInoutType(con,context,loginContext);
			InoutType obj = InoutType.fetch();
			InoutTypePageData data = (InoutTypePageData)PageData.fromTable(obj,InoutTypePageData.class);
			context.setValue("InoutTypePageData",data);
			context.setNextUrl(path+"InoutTypeEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListInoutType"))
		{
			backInoutType(con,context,path);
			return;
		}
		
		//add by Sindy start

		//add by Sindy end

		Logger.throwException("InoutTypeSrv","unknown action_code="+action_code);
	}
}
